#ifndef __CALIBRATION_H
#define __CALIBRATION_H

#include "sys.h"
#include <stdint.h>

#define CALIBRATION_MAX_POINTS 20

typedef struct
{
    float x;
    float y;
} calibration_point_t;

typedef struct
{
    float a;
    float b;
    float c;
    float d;
    float max;
} cubic_param_t;

typedef struct
{
    float k;
    float b;
} linear_param_t;

int CalibrationStartFit(void *arg, uint8_t count);
int CubicFit(cubic_param_t *param, const calibration_point_t *points, int n);
int LinearFit(linear_param_t *param, const singly_linked_list_t *head, int n);
uint8_t CalibrationPointRecord(uint8_t index, float x, float y);
float CalculateForwardPower(cubic_param_t *param, float x);
float CalculateSWR(float forward, float reverse);

float CalculateVoltageToDBm(float voltage, float slope, float intercept);
float CalculateDBmToWatt(float dBm);

#endif // __CALIBRATION_H
